/**
 * @file ps2.h
 *
 * @brief:
 * @author ted.huang
 * @email <tednick@163.com.>
 * @version V1.0
 * @date 2021-05-09
 */

#ifndef __PS2_H_
#define __PS2_H_

#ifdef __cplusplus
extern "C"{
#endif

enum {
	PS2_KEY_SELECT,
	PS2_KEY_L3,
	PS2_KEY_R3,
	PS2_KEY_START,
	PS2_KEY_UP,
	PS2_KEY_RIGHT,
	PS2_KEY_DOWN,
	PS2_KEY_LEFT,
	PS2_KEY_L2,
	PS2_KEY_R2,
	PS2_KEY_L1,
	PS2_KEY_R1,
	PS2_KEY_TRIANGLE,
	PS2_KEY_ROUNDNES,
	PS2_KEY_X,
	PS2_KEY_SQUARE,
	PS2_KEY_MAX,
};

enum {
	PS2_JOYSTICK_LEFT_UP,
	PS2_JOYSTICK_LEFT_DOWN,
	PS2_JOYSTICK_LEFT_LEFT,
	PS2_JOYSTICK_LEFT_RIGHT,
	PS2_JOYSTICK_RIGHT_UP,
	PS2_JOYSTICK_RIGHT_DOWN,
	PS2_JOYSTICK_RIGHT_LEFT,
	PS2_JOYSTICK_RIGHT_RIGHT,
	PS2_JOYSTICK_MAX,
};

typedef void * Ps2ObjHdl;

typedef struct {
	void (*selChipCb)(int level);
	void (*spiXferCb)(unsigned char *tx, unsigned char *rx, int len);
	void (*delayUsCb)(unsigned int us);
	void (*delayMsCb)(unsigned int ms);
} Ps2CbStru;


void Ps2RegisterMalloc(void *(*malloc)(unsigned int size), void (*free)(void *ptr));
Ps2ObjHdl Ps2Init(Ps2CbStru *cfg);
void Ps2Deinit(Ps2ObjHdl hdl);
int Ps2GetState(Ps2ObjHdl hdl,
                unsigned char key[PS2_KEY_MAX], int *keyLen,
                unsigned char joystick[PS2_JOYSTICK_MAX]);
int Ps2GetAllState(Ps2ObjHdl hdl, unsigned char key[PS2_KEY_MAX],
                unsigned char joystick[PS2_JOYSTICK_MAX]);
void Ps2ShowKey(unsigned char key);
void Ps2ShowJoystick(unsigned char joystick, unsigned char value);


#ifdef __cplusplus
}
#endif

#endif /* __PS2_H_ */

